package com.example.chasshelper;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.chasshelper.adapter.ClassroomTeaAdapter;
import com.example.chasshelper.dao.ClassroomDao;
import com.example.chasshelper.dao.CourseDao;
import com.example.chasshelper.dao.MessageDao;
import com.example.chasshelper.dao.RegistrationDao;
import com.example.chasshelper.dao.SolutionDao;
import com.example.chasshelper.dao.StudentDao;
import com.example.chasshelper.dao.TeacherDao;
import com.example.chasshelper.dao.TestDao;
import com.example.chasshelper.model.Classroom;
import com.example.chasshelper.model.Student;
import com.example.chasshelper.model.Teacher;
import com.example.chasshelper.model.Test;
import com.example.chasshelper.utils.DaoUtils;

import java.util.ArrayList;
import java.util.List;

public class AddTestActivity extends AppCompatActivity implements View.OnClickListener{
    private static final String TAG = AddTestActivity.class.getSimpleName();
    private final Activity mContext = AddTestActivity.this;
    //控件
    private ImageView iv_back;
    private RecyclerView rv_classroom_tea;

    //dao
    private TeacherDao teacherDao= DaoUtils.getTeacherDao();
    private StudentDao studentDao=DaoUtils.getStudentDao();
    private CourseDao courseDao=DaoUtils.getCourseDao();
    private ClassroomDao classroomDao=DaoUtils.getClassroomDao();
    private RegistrationDao registrationDao=DaoUtils.getRegistrationDao();
    private SolutionDao solutionDao = DaoUtils.getSolutionDao();
    private MessageDao messageDao = DaoUtils.getMessageDao();
    private TestDao testDao = DaoUtils.getTestDao();
    //数据
    private Teacher teacher;
    private ArrayList<Test> addTest;
    private List<Classroom> classroomList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_test);
        //线程
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        //初始化界面
        initUI();
        //初始化数据
        initData();

    }
    private void initUI() {
        //绑定控件
        iv_back = findViewById(R.id.iv_back);
        rv_classroom_tea = findViewById(R.id.rv_classroom_tea);
        //点击事件
        iv_back.setOnClickListener(this);
    }

    private void initData() {
        teacher = (Teacher) getIntent().getSerializableExtra("teacher");
        //adapter实例化
        classroomList = classroomDao.findByTeacherId(teacher);
        addTest = (ArrayList<Test>) getIntent().getSerializableExtra("addTest");
        //adapter初始化，并向adapter传递数据
        ClassroomAddTestAdapter classroomAddTestAdapter = new ClassroomAddTestAdapter(mContext,classroomList,addTest,teacher);
        rv_classroom_tea.setLayoutManager(new LinearLayoutManager(mContext));
        rv_classroom_tea.setAdapter(classroomAddTestAdapter);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back://返回
                finish();
            break;
        }
    }
}
